<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学号" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入学号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请学分" prop="applyScore">
        <el-input
          v-model="queryParams.applyScore"
          placeholder="请输入申请学分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人员编号" prop="auditorId">
        <el-input
          v-model="queryParams.auditorId"
          placeholder="请输入审核人员编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审定学分" prop="auditorScore">
        <el-input
          v-model="queryParams.auditorScore"
          placeholder="请输入审定学分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审批状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_app_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:application:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:application:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:application:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:application:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="applicationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="申请序号" align="center" prop="appId" />
      <el-table-column label="学号" align="center" prop="userId" />
      <el-table-column label="项目类型" align="center" prop="projectType" />
      <el-table-column label="项目内容" align="center" prop="projectContent" />
      <el-table-column label="申请学分" align="center" prop="applyScore" />
<!--      <el-table-column label="审核人员编号" align="center" prop="auditorId" />-->
      <el-table-column label="审定学分" align="center" prop="auditorScore" />
      <el-table-column label="审批状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_app_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
<!--      <el-table-column label="附件id" align="center" prop="attachIds" />-->
<!--      <el-table-column label="审核意见" align="center" prop="reviewComment" />-->
<!--      <el-table-column label="申请时间" align="center" prop="applyTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.applyTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="审定日期" align="center" prop="auditorTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.auditorTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="项目时间" align="center" prop="projectTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.projectTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleInfo(scope.row)"
            v-hasPermi="['system:application:query']"
          >详情</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:application:edit']"
          >修改</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:application:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学分审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学号" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="项目内容">
          <editor v-model="form.projectContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="申请学分" prop="applyScore">
          <el-input v-model="form.applyScore" placeholder="请输入申请学分" />
        </el-form-item>
        <el-form-item label="审核人员编号" prop="auditorId">
          <el-input v-model="form.auditorId" placeholder="请输入审核人员编号" />
        </el-form-item>
        <el-form-item label="审定学分" prop="auditorScore">
          <el-input v-model="form.auditorScore" placeholder="请输入审定学分" />
        </el-form-item>
        <el-form-item label="审批状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_app_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="附件id" prop="attachIds">
          <el-input v-model="form.attachIds" placeholder="请输入附件id" />
        </el-form-item>
        <el-form-item label="审核意见" prop="reviewComment">
          <el-input v-model="form.reviewComment" placeholder="请输入审核意见" />
        </el-form-item>
        <el-form-item label="申请时间" prop="applyTime">
          <el-date-picker clearable
            v-model="form.applyTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审定日期" prop="auditorTime">
          <el-date-picker clearable
            v-model="form.auditorTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审定日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目时间" prop="projectTime">
          <el-date-picker clearable
            v-model="form.projectTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择项目时间">
          </el-date-picker>
        </el-form-item>
<!--        <el-divider content-position="center">项目管理信息</el-divider>-->
<!--        <el-row :gutter="10" class="mb8">-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddSysProjectCategory">添加</el-button>-->
<!--          </el-col>-->
<!--          <el-col :span="1.5">-->
<!--            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteSysProjectCategory">删除</el-button>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--        <el-table :data="sysProjectCategoryList" :row-class-name="rowSysProjectCategoryIndex" @selection-change="handleSysProjectCategorySelectionChange" ref="sysProjectCategory">-->
<!--          <el-table-column type="selection" width="50" align="center" />-->
<!--          <el-table-column label="序号" align="center" prop="index" width="50"/>-->
<!--          <el-table-column label="项目名称" prop="name" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.name" placeholder="请输入项目名称" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="状态0-启用 1-关闭" prop="status" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-select v-model="scope.row.status" placeholder="请选择状态0-启用 1-关闭">-->
<!--                <el-option-->
<!--                  v-for="dict in dict.type.sys_job_status"-->
<!--                  :key="dict.value"-->
<!--                  :label="dict.label"-->
<!--                  :value="dict.value"-->
<!--                ></el-option>-->
<!--              </el-select>-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="创建人" prop="userId" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.userId" placeholder="请输入创建人" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="分值" prop="score" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.score" placeholder="请输入分值" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="描述" prop="description" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.description" placeholder="请输入描述" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="创建时间" prop="createTime" width="240">-->
<!--            <template slot-scope="scope">-->
<!--              <el-date-picker clearable v-model="scope.row.createTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择创建时间" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="修改时间" prop="updateTime" width="240">-->
<!--            <template slot-scope="scope">-->
<!--              <el-date-picker clearable v-model="scope.row.updateTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择修改时间" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="说明" prop="comment" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.comment" placeholder="请输入说明" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="父级id" prop="parentId" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.parentId" placeholder="请输入父级id" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="父级id集" prop="parentIds" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.parentIds" placeholder="请输入父级id集" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="排序" prop="sort" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.sort" placeholder="请输入排序" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--          <el-table-column label="用户登录ip地址" prop="ip" width="150">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.ip" placeholder="请输入用户登录ip地址" />-->
<!--            </template>-->
<!--          </el-table-column>-->
<!--        </el-table>-->
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="InfoLog">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApplication, getApplication, delApplication, addApplication, updateApplication } from "@/api/system/application";

export default {
  name: "Application",
  dicts: ['sys_job_status', 'sys_app_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedSysProjectCategory: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学分审核表格数据
      applicationList: [],
      // 项目管理表格数据
      sysProjectCategoryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        projectType: null,
        projectContent: null,
        applyScore: null,
        auditorId: null,
        auditorScore: null,
        status: null,
        attachIds: null,
        reviewComment: null,
        applyTime: null,
        auditorTime: null,
        projectTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //详情页面
      InfoLog: true
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学分审核列表 */
    getList() {
      this.loading = true;
      listApplication(this.queryParams).then(response => {
        this.applicationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        appId: null,
        userId: null,
        projectType: null,
        projectContent: null,
        applyScore: null,
        auditorId: null,
        auditorScore: null,
        status: 0,
        remark: null,
        attachIds: null,
        reviewComment: null,
        applyTime: null,
        auditorTime: null,
        projectTime: null
      };
      this.sysProjectCategoryList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.appId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.InfoLog=true;
      this.reset();
      this.open = true;
      this.title = "添加学分审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.InfoLog=true;
      this.reset();
      const appId = row.appId || this.ids
      getApplication(appId).then(response => {
        this.form = response.data;
        this.sysProjectCategoryList = response.data.sysProjectCategoryList;
        this.open = true;
        this.title = "修改学分审核";
      });
    },
    /** 详情按钮操作 */
    handleInfo(row) {
      this.InfoLog=false;
      this.reset();
      const appId = row.appId || this.ids
      getApplication(appId).then(response => {
        this.form = response.data;
        this.sysProjectCategoryList = response.data.sysProjectCategoryList;
        this.open = true;
        this.title = "学分审核详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.sysProjectCategoryList = this.sysProjectCategoryList;
          if (this.form.appId != null) {
            updateApplication(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApplication(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const appIds = row.appId || this.ids;
      this.$modal.confirm('是否确认删除学分审核编号为"' + appIds + '"的数据项？').then(function() {
        return delApplication(appIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 项目管理序号 */
    rowSysProjectCategoryIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 项目管理添加按钮操作 */
    handleAddSysProjectCategory() {
      let obj = {};
      obj.name = "";
      obj.status = "";
      obj.userId = "";
      obj.score = "";
      obj.description = "";
      obj.createTime = "";
      obj.updateTime = "";
      obj.comment = "";
      obj.parentId = "";
      obj.parentIds = "";
      obj.sort = "";
      obj.ip = "";
      this.sysProjectCategoryList.push(obj);
    },
    /** 项目管理删除按钮操作 */
    handleDeleteSysProjectCategory() {
      if (this.checkedSysProjectCategory.length == 0) {
        this.$modal.msgError("请先选择要删除的项目管理数据");
      } else {
        const sysProjectCategoryList = this.sysProjectCategoryList;
        const checkedSysProjectCategory = this.checkedSysProjectCategory;
        this.sysProjectCategoryList = sysProjectCategoryList.filter(function(item) {
          return checkedSysProjectCategory.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleSysProjectCategorySelectionChange(selection) {
      this.checkedSysProjectCategory = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/application/export', {
        ...this.queryParams
      }, `application_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
